package com.yunao.commons.serachcore.core.bean;

import com.yunao.service.report.bean.compare.ComparatorByKey;
import com.yunao.service.report.bean.compare.ComparatorByValue;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Groups extends BaseEntities implements Serializable {

	private static final long serialVersionUID = 1L;

	private long total;
	private long size;
	private List<Group> data;

	public Groups() {

	}

	public Groups(long total) {
		this.total = total;
	}

	public Long getTotal() {
		return total;
	}

	public Long getSize() {
		return size;
	}

	public List<Group> getData() {
		if (data == null) {
			return Collections.emptyList();
		}
		return data;
	}

	public void addData(Group e) {
		if (data == null) {
			data = new ArrayList<>();
		}
		data.add(e);
		size++;
	}
	public void sortByKey() {
		Collections.sort(data, new ComparatorByKey<Group>());
	}

	public void sortByValue() {
		Collections.sort(data, new ComparatorByValue<Group>());
	}

	@Override
	public String toString() {
		return toString(total, size, data);
	}

}
